package com.homegoods.designer.item;

import android.view.View.OnLongClickListener;

import com.homegoods.designer.R;
import com.homegoods.designer.model.EditDesignCase2Model;
import com.kedll.library.adapter.MultiTypeAdapter;
import com.kedll.library.dialog.ECAlertDialog;
import com.kedll.library.mvp.BaseItem;
import com.kedll.library.util.CollectionUtils;

import java.util.Locale;

/**
 * @author QiQi
 * @ClassName: EditDesignCase2Item
 * @date 2018/10/7
 * @description
 */
public class EditDesignCase2Item extends BaseItem<EditDesignCase2Model> {
    private OnLongClickListener onLongClickListener;

    public EditDesignCase2Item(EditDesignCase2Model data, MultiTypeAdapter adapter) {
        super(data);
        setOnClickListener(v -> {
            if (adapter.getOnItemClickListener() != null) {
                adapter.getOnItemClickListener().onItemClicked(v,this);
            }
        });

        setOnLongClickListener(v -> {
            ECAlertDialog dialog = ECAlertDialog.buildAlert(v.getContext(), "确定删除这个空间？", (dialog1, which) -> {
                int position = adapter.findPos(this);
                adapter.removeItem(this);
                adapter.notifyItemRemoved(position);
            });
            dialog.show();

            return true;
        });

    }

    public void setOnLongClickListener(OnLongClickListener onLongClickListener) {
        this.onLongClickListener = onLongClickListener;
    }

    public String getTitle() {
        return getData().getTitle();
    }

    public String getPics() {
        return String.format(Locale.ROOT, "%d张", CollectionUtils.size(getData().getPics()));
    }

    public OnLongClickListener getOnLongClick() {
        return onLongClickListener;
    }

    @Override
    public int getLayout() {
        return R.layout.designer_item_space;
    }
}
